<template>
  <div class="OctopusBottomBar">
    <!--    <div class="containerMask"></div>-->
    <!--    <div class="icon iconxinxitishi">44</div>-->
    <!--    <span class=" icon iconjinbi" style="color: #4AFD88; ;font-size:14px;">55</span>-->
    <van-tabbar v-model="active" v-bind:border="false" v-bind:class="octopus.passport.bangs ? 'isBangs' : ''"
                :safe-area-inset-bottom="false">
      <van-tabbar-item name="Home" to="/main/app/campus/login">
        <van-icon class="iconhome" class-prefix="iconfont" slot="icon" slot-scope="props"></van-icon>
        <span>首页</span>
      </van-tabbar-item>
      <van-tabbar-item name="School" to="/APP/Campus/Communicate/ClassGroup/Management">
        <van-icon class="iconqun-copy" class-prefix="iconfont" slot="icon" slot-scope="props"></van-icon>
        <span>班级群</span>
      </van-tabbar-item>
      <van-tabbar-item name="Message" :info="InfoCount > 0 ? InfoCount : ''" to="/APP/Campus/MessageCenter/Page">
        <van-icon class="iconxiaoxi1" class-prefix="iconfont" slot="icon" slot-scope="props"></van-icon>
        <span>消息中心</span>
      </van-tabbar-item>
      <van-tabbar-item name="Healthy" to="/APP/Campus/Healthy/Home/Page">
        <van-icon class="iconjiankang" class-prefix="iconfont" slot="icon" slot-scope="props"></van-icon>
        <span>健康中心</span>
      </van-tabbar-item>
      <van-tabbar-item name="Mine" to="/APP/Campus/User/Home/Page">
        <van-icon class="iconwodehuise-01" class-prefix="iconfont" slot="icon" slot-scope="props"></van-icon>
        <span>我的</span>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
  export default {
    name: "MenuEngine" /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */,
    data() {
      return {
        octopus: this.$parent.octopus,
        active: "Home",
        InfoCount: 0,
        changedInfoCountID: 328,
        ClassID: '',
        ProjectID: '',
      };
    },
    created: function () {
      this.init();
    },
    updated: function () {
      this.octopus.tips.debug("[AppMenuEngine执行了updated事件。");
    },
    // 活动事件，写在这里的好处是不管是第一次创建还是后退回来，都会触发这个事件
    // 比较典型的就是列表组件，返回的时候往往是需要刷新的。
    activated: function () {
      this.init();
    },
    // 组件停用时，也就是切换出去的时候，需要注意的是，AppMenuEngine组件切换出去，不允许缓存，需要释放到初始状态，以便于下次进来。
    deactivated: function () {
      // this.destroyData();
      this.octopus.tips.debug("AppMenuEngine执行了deactivated事件。");
    },
    computed: {
      // 如果cellData数据发生了改变,则触发这个事件。
      changeCell: function () {
        return this.source.id;
      },
      changePage: function () {
      },
    },
    methods: {
      init: function () {
        // 存在校园数据才执行
        if (this.octopus.passport.campus) {
          if (this.octopus.passport.typeID == 1) {
            this.ClassID = this.octopus.passport.campus.teacher.classID;
            this.ProjectID = this.octopus.passport.campus.teacher.schoolID;
            this.changedInfoCountID = 328;
          } else {
            this.ClassID = this.octopus.passport.campus.parent.classID;
            this.ProjectID = this.octopus.passport.campus.parent.schoolID;
            this.changedInfoCountID = 330;
          }
          this.changedInfoCount();
          this.load();
        }
      },
      // 测试vant调用摄像头
      load: function () {
        let modelurl = this.octopus.router.get().fullPath.toLocaleLowerCase();
        if (modelurl.indexOf("/campus/home/page") > -1) {
          this.active = "Home";
        } else if (modelurl.indexOf("/campus/messagecenter/page") > -1) {
          this.active = "Message";
        } else if (modelurl.indexOf("campus/communicate/classgroup") > -1) {
          this.active = "School";
        } else if (modelurl.indexOf("/campus/healthy/home/page") > -1) {
          this.active = "Healthy";
        } else if (modelurl.indexOf("/campus/user/home/page") > -1) {
          this.active = "Mine";
        } else {
          this.active = "Home";
        }
      },
      //获取班级未读消息数
      changedInfoCount() {
        this.octopus.request.api.post("/Octopus/Engine/List", {
            id: this.changedInfoCountID,
            cellData: [
              {name: "UnreadNumber"}, //内容
              {name: "ClassID", filterKey: "=", filterValue: this.ClassID}, //头像
              {name: "SchoolID", filterKey: "=", filterValue: this.ProjectID}, //校区ID
              {name: "UserID", filterKey: "=", filterValue: this.octopus.passport.id}, //用户
            ],
          },
          (data) => {
            if (data.status.code === 200) {
              if(data.content.queryData.length > 0){
                this.InfoCount = data.content.queryData[0].UnreadNumber;
              }
            } else {
              this.octopus.tips.error(data);
            }
          }
        )
      },
    },
    watch: {},
    props: ["changed"],
  };
</script>
